<?php
$form = $this->form;
if(isset($this->thongtinsanpham)){
	$data = $this->thongtinsanpham;
	$hinhAnh = explode('|', $data->hinhAnh);
	// link ảnh
	$linkimg = '/files/'.$data->loaiHang.'/'.$data->maHang.'/';	
?>
<div class="" id="admin-content">
	<form class="form-horizontal" role="form" action="/admin/manage/edit/id/<?php echo $data->id; ?>" method="post" enctype="multipart/form-data" style="width: 80%; margin:0px auto; margin-top:12px;">
		<div class="form-group">
			<label class="col-sm-3 control-label" for="maHang">Mã sản phẩm</label>		
			<div class="col-sm-5">
				<input name="maHang" type="text" required="required" id="maHang" class="form-control" value="<?php echo $data->maHang; ?>" readonly>
			</div>		
		</div>

		<div class="form-group">
			<label class="col-sm-3 control-label" for="ten">Tên sản phẩm</label>		
			<div class="col-sm-5">
				<input name="ten" type="text" required="required" id="ten" class="form-control" value="<?php echo $data->ten; ?>" >
			</div>		
		</div>

		<div class="form-group">
			<label class="col-sm-3 control-label" for="soLuongNhapVao">Số lượng nhập vào</label>		
			<div class="col-sm-5">
				<input name="soLuongNhapVao" type="text" required="required" id="soLuongNhapVao" class="form-control" value="<?php echo $data->soLuongNhapVao; ?>" >
			</div>		
		</div>

		<div class="form-group">
			<label class="col-sm-3 control-label" for="soLuong">Số lượng</label>		
			<div class="col-sm-5">
				<input name="soLuong" type="text" required="required" id="soLuong" class="form-control" value="<?php echo $data->soLuong; ?>" onclick="clickModal();">
			</div>		
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label" for="tinhTrang">Tình trạng</label>		
			<div class="col-sm-5">
				<input name="tinhTrang" type="text" required="required" id="tinhTrang" class="form-control" value="<?php echo $data->tinhTrang; ?>" readonly>
			</div>		
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label" for="ngayNhap">Ngày nhập</label>		
			<div class="col-sm-5">
				<input name="ngayNhap" type="date" required="required" id="ngayNhap" class="form-control" value="<?php echo $data->ngayNhap; ?>" readonly>
			</div>		
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label" for="loaiHang">Loại hàng</label>		
			<div class="col-sm-5">
				<select name="loaiHang" id="loaiHang" class="form-control" readonly>
					<option value="1" <?php if($data->loaiHang==1) echo 'default';?>>Giày dép</option>
					<option value="2" <?php if($data->loaiHang==2) echo 'default';?>>Túi xách</option>
				</select>
			</div>		
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label" for="gia">Giá nhập</label>		
			<div class="col-sm-5">
				<input name="gia" type="text" required="required" id="gia" class="form-control" value="<?php echo $data->gia; ?>" readonly>
			</div>		
		</div>

		<div class="form-group">
			<label class="col-sm-3 control-label" for="giaBan">Giá bán</label>		
			<div class="col-sm-5">
				<input name="giaBan" type="text" required="required" id="giaBan" class="form-control" value="<?php echo $data->giaBan; ?>" >
			</div>		
		</div>

		<div class="form-group">
			<label class="col-sm-3 control-label" for="moTa">Mô tả</label>		
			<div class="col-sm-7">
				<textarea name="moTa" height="200px" required="required" id="moTa" class="form-control">
					<?php echo trim($data->moTa); ?>
				</textarea>
			</div>		
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label" for="hinhAnh1">Hình ảnh 1</label>		
			<div class="col-sm-5">
				<input name="hinhAnh1" type="file" id="hinhAnh1" class="form-control" value="">
				<?php 
					if(isset($hinhAnh[0]) && $hinhAnh[0]!=NULL)
						echo "<br/><img id='myimg' onerror='imgError(this)'	 width='100%'  src=".$linkimg.$hinhAnh[0]."><br/><a style='margin-top:5px;' class='btn btn-danger'>Xóa ảnh</a>";
				?>
			</div>		
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label" for="hinhAnh2">Hình ảnh 2</label>		
			<div class="col-sm-5">
				<input name="hinhAnh2" type="file" id="hinhAnh2" class="form-control" value="">
				<?php 
					if(isset($hinhAnh[1]) && $hinhAnh[1]!=NULL)
						echo "<br/><img id='myimg' onerror='imgError(this)'	 width='100%' src=".$linkimg.$hinhAnh[1]."><br/><a style='margin-top:5px;' class='btn btn-danger'>Xóa ảnh</a>";
				?>
			</div>		
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label" for="hinhAnh3">Hình ảnh 3</label>		
			<div class="col-sm-5">
				<input name="hinhAnh3" type="file" id="hinhAnh3" class="form-control" value="">
				<?php 
					if(isset($hinhAnh[2]) && $hinhAnh[2]!=NULL)
						echo "<br/><img id='myimg' onerror='imgError(this)'	 width='100%' src=".$linkimg.$hinhAnh[2]."><br/><a style='margin-top:5px;' class='btn btn-danger'>Xóa ảnh</a>";
				?>
			</div>		
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label" for="change">Thay đổi</label>		
			<div class="col-sm-5">
				<input name="change" type="text" id="change" class="form-control" value="" readonly>
			</div>		
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label"></label>		
			<div class="col-sm-5">
				<input name="submit" type="submit" id="submit" class="btn btn-primary" value="Sửa">
			</div>		
		</div>
	</form>
	<button class="btn btn-primary btn-lg hidden" type="button" data-toggle="modal" data-target="#myModal" id="showModalButton">
	</button>

	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
						<h4 class="modal-title" id="myModalLabel">Cập nhật số lượng có sẵn</h4>
					</div>
					<div class="modal-body" id="slct">
					<form class="form-horizontal" role="form" name="otherForm">
						<?php 
							$vals = explode("|", $data->tinhTrang);
							$counter = 0;
							for($i = 34; $i < 41; $i++){
							echo '
							<div class="form-group">
								<label class="col-sm-3 control-label" for="size'.$i.'">
								 Size '.$i.'
								</label>
								<div class="col-sm-4">
									<input type="text" id="size'.$i.'" class="form-control" placeholder="Số lượng có sẵn" value="'.$vals[$counter].'"/>
								</div>
							</div>
							';
							$counter++;
						}?>
					</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal" onclick="saveChanges();">Close</button>
					</div>
				</div>
			</div>
		</div>

</div>
<?php }?>
<script>
	var x = $('textarea[name=moTa');
	var b = x.val();
	b = b.trim();
	x.val(b);

	function clickModal(){
		$('#showModalButton').click();
	}

	var inputs;
	var vals;	
	var slct = '';
	function saveChanges(){
		console.log("save changes");
		var inputs = $('#slct input');	
		var sum = 0;
		var slct = '';
		for(i = 0; i < inputs.length; i++){
			sum += parseInt($(inputs[i]).val());
			if(i != inputs.length - 1)
				slct = slct + $(inputs[i]).val() +"|";
			else
				slct = slct + $(inputs[i]).val();
 		}
 		$('#soLuong').val(sum);
 		$('#tinhTrang').val(slct);
	}

	function changeImage(e){
		
	}
</script>